package spells;
import creatures.*;
import main.*;
/*
 * basic damage spell
 */
import main.Creature;

public class Tidalsurge extends Spell{
   
    /**
     * A damaging attack that significantly slows the target.
     */
   
    public Tidalsurge()
    {
        hasTarget = true;
        element = "water";
        name="Tidalsurge";
        description="A damaging attack that significantly slows the target.\nPrimary stats:Intelligence\nRange=4";
        castTime = 1;
        range=4;
    }
   
    public Tidalsurge(Creature caster)
    {
        this.caster=caster;
        hasTarget = true;
        element = "water";
        name="Tidalsurge";
        description="A damaging attack that significantly slows the target.\nPrimary stats:Intelligence\nRange=4";
        castTime = 1;
        range=4;
    }
   
    public void setCaster(Creature c){
        caster=c;
        cManaChange=caster.level*-5;
    }//end method
   
    public String applySpell(Grid g){
        cManaChange = caster.level * -2;
        healthChange = -1*(2*RandNum.randNum(1,2) + caster.intelligence);
        movementChange = 1;
        if(target!=null || !hasTarget){
            double distance;
            if(hasTarget)
                distance=g.getDToEnemy(target);
            else
                distance=0;
            if(caster.curMana+cManaChange>=0 && distance<=range){
                //do effect to target if there is a target
                if(hasTarget){
                    target.curHealth+=healthChange;
                    target.strength+=strChange;
                    target.stamina+=stamChange;
                    target.intelligence+=intChange;
                    target.spirit+=spChange;
                    target.curMana+=manaChange;
                    target.movementSpeed+=movementChange;
                    if(target.curHealth<0)
                        target.curHealth=0;
                    if(target.curHealth>target.maxHealth)
                        target.curHealth=target.maxHealth;
                    if(target.curMana<0)
                        target.curMana=0;
                    if(target.curMana>target.maxMana)
                        target.curMana=target.maxMana;
                }//end if
               
                //do effect to caster
                caster.curHealth+=cHealthChange;
                caster.strength+=cStrChange;
                caster.stamina+=cStamChange;
                caster.intelligence+=cIntChange;
                caster.spirit+=cSpChange;
                caster.curMana+=cManaChange;
                if(caster.curHealth<0)
                    caster.curHealth=0;
                if(caster.curHealth>caster.maxHealth)
                    caster.curHealth=caster.maxHealth;
                if(caster.curMana<0)
                    caster.curMana=0;
                if(caster.curMana>caster.maxMana)
                    caster.curMana=caster.maxMana;
               
                //determines what spell message to say
                if(hasTarget){
                    StatChange lessSpeed = new StatChange(3);
                    lessSpeed.movementChange = cMovementChange;
                    lessSpeed.setName("Windwhipped");
                    target.buffs.add(lessSpeed);
                    return caster.name+" has cast "+name+" at "+target.name+" dealing "+healthChange+" damage";
                }
            }//end if
            //if you are out of range
            else if(distance>range){
                return "Out of range";
            }
            //if you are out of mana
            else{
               
                return "Not enough mana";
            }//end else
        }//end if
        return "";
    }//end method
   
}
